#pragma once

#include "precomp.h"
#include "program.h"

class RingRenderBatcher : public CL_RenderBatcher
{
public:
	RingRenderBatcher(CL_GraphicContext &gc, CL_String program_name, CL_ResourceManager *resources);

	void draw_ring(CL_GraphicContext &gc, const CL_Rectf &size, const CL_Rect &frame, const CL_Texture &texture, float x, float y, float r, float s, float sa, CL_Colorf c);
	void flush(CL_GraphicContext &gc);
	void modelview_changed(const CL_Mat4f &modelview);
private:
	static CL_ProgramObject create_shader_program(CL_GraphicContext &gc, CL_String resource_id, CL_ResourceManager *resources);

	enum { num_vertices = 6*4096 };
	CL_Vec2f positions[num_vertices];
	CL_Vec4f colors[num_vertices];
	CL_Vec2f tex1_coords[num_vertices];
	int cur_position;
	CL_Texture current_texture;

	CL_ProgramObject program;
};


class RingSprite
{
public:
	RingSprite();
	RingSprite(CL_GraphicContext &gc, RingRenderBatcher *batcher_, const CL_String &name, CL_ResourceManager *resources);
	~RingSprite();

	void draw_ring(CL_GraphicContext &gc, float x, float y, float r, float s, float sa, CL_Colorf color=CL_Colorf(1.f, 1.f, 1.f, 1.f)); // x, y, r - radius, s - ring size, sa - start angle
	void set_frame(int f);

	std::vector<CL_Rect> frames;
private:
	RingRenderBatcher *batcher;
	CL_Rect geometry;
	CL_Texture texture;
	int cur_frame;
};

